<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends BaseController{

    public function route()
    {
        $action=I('get.act');
        $nav=M('category')->where('pid=0')->field('action')->select();
        $navs = array_column($nav, 'action');
        if(in_array($action,$navs)){
            $this->redirect('index/'.$action);
        }else{
            $this->redirect("index");
        }

    }
    
    public function index(){
        $action=ACTION_NAME;
        $this->assign("action",$action);
        $cate=M('category')->alias("b")->where('b.pid=1')->select();
         foreach($cate as $k=>$v){
            $cate[$k]['children']=M('post')->where('cate_id=%d',$v['id'])->select();
         }

         $this->assign("cate",$cate);
         $this->display();
    }


    public function content()
    {
        $action=ACTION_NAME;
        $this->assign("action",$action);
        //新闻页不同
        $id=I('get.id');
        $cates=M('category')->alias("b")->where('b.pid=%d',$id)->select();
        foreach($cates as $k=>$v){
            $cates[$k]['children']=M('post')->where('cate_id=%d',$v['id'])->select();
        }
    }

    //新闻咨讯
    public function news()
    {
        $action=ACTION_NAME;
        $this->assign("action",$action);
        $cate_id=M('category')->where('action="'.$action.'"')->field('id')->find();
        $cate=M('category')->where('pid=%d',$cate_id['id'])->select();
        foreach($cate as $k=>$v){
            $cate[$k]['children']=M('post')->where('cate_id=%d',$v['id'])->select();
        }
//        dd($cate);
        $this->assign('cate',$cate);
        $this->display();
    }




    //关于仁义邦
    public function about()
    {
        $action=ACTION_NAME;
        $this->assign("action",$action);

        $cate_id=M('category')->where('action="'.$action.'"')->field('id')->find();
        $cate=M('category')->where('pid=%d',$cate_id['id'])->select();
        foreach($cate as $k=>$v){
            $cate[$k]['children']=M('post')->where('cate_id=%d',$v['id'])->select();
        }

        $this->assign('cate',$cate);
        $this->display();

    }

    //业务范畴
    public function business()
    {
        $action=ACTION_NAME;
        $this->assign("action",$action);

        $cate_id=M('category')->where('action="'.$action.'"')->field('id')->find();
        $cate=M('category')->where('pid=%d',$cate_id['id'])->select();
        foreach($cate as $k=>$v){
            $cate[$k]['children']=M('post')->where('cate_id=%d',$v['id'])->select();
        }

        $this->assign('cate',$cate);

        $this->display();
    }

    //新闻咨讯
    public function service()
    {
        $action=ACTION_NAME;
        $this->assign("action",$action);
        $cate_id=M('category')->where('action="'.$action.'"')->field('id')->find();

        $data= M('post')->where('cate_id=%d',$cate_id['id'])->find();

        $this->assign('data',$data);
        $this->display();
    }


    //联系我们
    public function contact()
    {
        $action=ACTION_NAME;
        $this->assign("action",$action);
        $this->display();
    }

    public function headers()
    {
        $this->display();
    }



    
    
}
